package com.sakura.thread.chapter7;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by apple on 2018/12/19.
 */
public class ReenTrantLockTest {
    final static ReentrantLock lock  = new ReentrantLock();

    public static void main(String[] args) {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                try{
                    Thread.sleep(10000);
                    System.out.println("测试锁是否阻塞A");
                }catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                try{
                    Thread.sleep(10000);
                    System.out.println("测试锁是否阻塞B");
                }catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        });

        threadA.start();
        threadB.start();


    }
}
